package com.dfbz.demo;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Demo02_ListIterator {

    public static void main(String[] args) {

        List<String> cates=new ArrayList<>();
        cates.add("南昌拌粉");
        cates.add("瓦罐汤");
        cates.add("三杯鸡");


        ListIterator<String> listIterator = cates.listIterator();

        while (listIterator.hasNext()){

            String cate = listIterator.next();

            if("瓦罐汤".equals(cate)){

                listIterator.add("辣椒好肉");
            }
        }

        System.out.println(cates);
 /*       Iterator<String> iterator = cates.iterator();

        while (iterator.hasNext()){
//            String cate = iterator.next();
//            System.out.println(cate);
//            iterator.remove();
            String cate = iterator.next();
            if("瓦罐汤".equals(cate)){
//                cates.remove(cate);
                cates.add("辣椒炒肉");          // Exception in thread "main" java.util.ConcurrentModificationException
            }
        }

        System.out.println(cates);*/


    }
    public static void test(String[] args) {


        List<String> cates=new ArrayList<>();
        cates.add("猪脚饭");
        cates.add("白切鸡");
        cates.add("肠粉");

        Iterator<String> iterator = cates.iterator();

        while (iterator.hasNext()){
            String cate = iterator.next();
            System.out.println(cate);
        }
        System.out.println("-----------");


        ListIterator<String> listIterator = cates.listIterator();
        System.out.println(listIterator.next());                // 猪脚饭
        System.out.println(listIterator.next());                // 白切鸡
        System.out.println(listIterator.next());                // 肠粉
        System.out.println("----------");
        System.out.println(listIterator.previous());            // 肠粉
        System.out.println(listIterator.previous());            // 白切鸡
        System.out.println(listIterator.previous());            // 猪脚饭
        System.out.println("----------");
        System.out.println(listIterator.next());                // 猪脚饭



    }
}
